<template>
  <div>
    <!-- 附件表五 基本信息及燃耗信息 add by qzn 20190710  -->
    <mt-header fixed title="道路货物运输量专项调查" style="z-index: 999999;">
      <span slot="left" @click="goBack">
        <mt-button icon="back" slot="left">返回</mt-button>
      </span>
      <mt-button  icon slot="right" @click.native="insertDate">新增</mt-button>
    </mt-header>
    <el-table border :data="tableData4" style="width: 100%" max-height="450">
      <el-table-column fixed prop="xh" label="序号" width="50" align="center"></el-table-column>
      <el-table-column prop="cphm" label="车牌号码" width="80" align="center"></el-table-column>
      <el-table-column prop="cpys" label="车牌颜色" width="80" align="center"></el-table-column>
      <el-table-column prop="cllx" label="车辆类型" width="80" align="center"></el-table-column>
      <el-table-column prop="bjdw" label="标记吨位(吨)" width="120" align="center"></el-table-column>
      <el-table-column prop="zzl" label="总质量(吨)" width="120" align="center"></el-table-column>
      <el-table-column prop="rllx" label="燃料类型" width="80" align="center"></el-table-column>
      <el-table-column prop="qtrllxmc" label="其他燃料类型名称" width="80" align="center"></el-table-column>
      <el-table-column prop="dcq" label="调查期" width="80" align="center"></el-table-column>
      <el-table-column prop="dcqq" label="调查期起" width="120" align="center"></el-table-column>
      <el-table-column prop="dcqz" label="调查期止" width="120" align="center"></el-table-column>
      <el-table-column prop="xslc" label="行驶里程(公里)" width="80" align="center"></el-table-column>
      <el-table-column prop="dcqqlcbds" label="调查期起里程表读数" width="120" align="center"></el-table-column>
      <el-table-column prop="dcqzlcbds" label="调查期止里程表读数" width="120" align="center"></el-table-column>
      <el-table-column prop="nh" label="能耗(升/立方米/千克/千万时)" width="120" align="center"></el-table-column>
      <el-table-column prop="bglnhjyz" label="百公里能耗经验值(升/立方米/千克/千瓦时)" width="120" align="center"></el-table-column>
      <el-table-column label="操作" width="120" align="center">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="deleteRow(scope.$index, tableData4)"
            type="text"
            size="small"
          >移除</el-button>
          <el-button @click.native.prevent="updateRow(scope.$index)" type="text" size="small">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
      
<script>
export default {
  data() {
    return {
      xh: 0, //序号
      tableData4: [
        {
          recid: "",
          floatorder: "",
          xh: '',
          cphm:'',// 车牌号码
          cpys: "", // 车牌颜色
          cllx: "", // 车辆类型
          bjdw: "", // 标记吨位
          zzl: "", // 总质量
          rllx: "", //燃料类型
          qtrllxmc: "",
          dcq: "", // 调查期
          dcqq: "", // 调查期起
          dcqz: "", //调查期止
          xslc: "", //行驶里程
          dcqqlcbds: "", // 调查期起里程表读数
          dcqzlcbds: "", // 调查期止里程表读数
          nh: "", // 能耗
          bglnhjyz: "", // 百公里能耗经验值
        }
      ],
      // 根据公司状态判定新增按钮是否显示 add by qzn 20190625
      reportedByOther: this.$route.query.reportedByOther,
       information:this.$route.query.information,
       userInfo:{}
    };
  },
  watch: {},
  mounted() {
    this.userInfo=JSON.parse(localStorage.getItem("userInfo")||{});
    this.getCode();

  },
  methods: {
    goBack() {
      //点击后退
      this.$router.go(-1);
    },
    getCode() {
      let data = {};
            data.companyType = this.userInfo.companyType;
      data.vehicleNo = this.userInfo.vehicleNo
      data.plateColorCode = this.userInfo.plateColorCode
      this.axios
        .post(
          "http://zxdc.catsic.com:9090/sampling/sjAssit/findFzdcbfd05ForSJ",
          { data: data },
          {
            headers: {
              "Content-Type": "application/json",
              mobileHeader:
                '{"sessionId":' + localStorage.getItem("sessionId") + "}"
            }
          }
        )
        .then(
          result => {
            console.log("restlut-->>"+JSON.stringify(result))
            if (result.data.status == "1000") {

                  
              this.tableData4.splice(0);
              
              if(result.data.data.MSG == "没有查询到结果"){
                  
              } else {
                   this.xh = 0;
                  result.data.data.Fzdcbfd05.forEach(item => {
                    let tableData = {};
                    tableData.recid = item.recid;
                    tableData.floatorder = item.floatorder;
                    tableData.xh = ++this.xh;
                    (tableData.cphm = item.fzdcbfd52019001), // 车牌号码
                    (tableData.cpys = item.fzdcbfd52019002), // 车牌颜色
                    (tableData.cllx = this.getCarTypeNmae(item.fzdcbfd52019003)), // 车辆类型
                    (tableData.bjdw = item.fzdcbfd52019004), // bjdw
                    (tableData.zzl = item.fzdcbfd52019005), // 总质量
                    (tableData.rllx = item.fzdcbfd52019006), // 
                    (tableData.qtrllxmc = item.fzdcbfd52019024),
                    
                    (tableData.dcq = this.getDcqName(item.fzdcbfd52019007)), // 调查期
                    (tableData.dcqq = item.fzdcbfd52019008), // 调查期起
                    (tableData.dcqz = item.fzdcbfd52019009), // 调查期止
                  //   (tableData.hlymc = this.getGoodsTypeNmae(item.fzdcbfd42019008)), // 货类1名称
                    (tableData.xslc = item.fzdcbfd52019010), // 行驶里程
                  //   (tableData.hlermc = this.getGoodsTypeNmae(item.fzdcbfd42019010)), // 货类2名称
                    (tableData.dcqqlcbds = item.fzdcbfd52019011), // 调查期起里程表读数
                  //   (tableData.hlsmc = this.getGoodsTypeNmae(item.fzdcbfd42019012)), // 货类3名称
                    (tableData.dcqzlcbds = item.fzdcbfd52019012), // 调查期止里程表读数
                    (tableData.nh = item.fzdcbfd52019013), // 能耗
                    (tableData.bglnhjyz = item.fzdcbfd52019014), // 百公里能耗经验值
                    this.tableData4.push(tableData);
                });
                
              }
              
            }
            // this.allgetCode();
          },
          error => {
            console.log("getyhcars request error:" + error);
          }
        );
    //   console.log(this.$route.query.yhmlk);
    },
    insertDate() {
      this.$router.push({
        path: "/main/auxiliaryTableFiveBaseInfoInsertSj/:yhmlk",
        query: { yhmlk: this.$route.query.yhmlk }
      });
    },
    deleteRow(index) {
      let data = {};
      data.recid = this.tableData4[index].recid;
      data.companyType=this.userInfo.companyType;
      this.axios
        .post(
          "http://zxdc.catsic.com:9090/sampling/sjAssit/deleteFzdcbfd05ForSJ",
          { data: data },
          {
            headers: {
              "Content-Type": "application/json",
              mobileHeader:
                '{"sessionId":' + localStorage.getItem("sessionId") + "}"
            }
          }
        )
        .then(
          result => {
            if (result.data.status == "1000") {
              this.getCode();
              console.log(result);
            }
          },
          error => {
            console.log("getyhcars request error:" + error);
          }
        );
      console.log(index, this.tableData4[index]);
      this.getCode();
    },
    updateRow(index) {
      this.$router.push({
        path: "/main/auxiliaryTableFiveBaseInfoUpdateSj/:yhmlk/:recid/:floatorder",
        query: {
          yhmlk: this.$route.query.yhmlk,
          recid: this.tableData4[index].recid,
          floatorder: this.tableData4[index].floatorder
        }
      });
      console.log(index, this.tableData4[index]);
    }, 
    getCarTypeNmae(code) {// 获取货物类型名称显示在表格 add by qzn 20190704  
      var carTypes = [
        {
        "code": "1",
        "name": "整车",
      },
      {
        "code": "1.1",
        "name": "集装箱车",
      },
      {
        "code": "1.2",
        "name": "冷藏保温车",
      },
      {
        "code": "1.3",
        "name": "其他",
      },
      {
        "code": "2",
        "name": "牵引车",
      },
      ];
      var name;
      carTypes.forEach(item => {
        if (item.code === code) {
          name = item.name;
        }
      });
      return name;
    },
    getDcqName(code) { 
      var carTypes = [
        {
        "code": "1",
        "name": "上旬（1-10日）",
      },
      {
        "code": "2",
        "name": "中旬（11-20日）",
      },
      {
        "code": "3",
        "name": "下旬（21-30日）",
      },
      {
        "code": "4",
        "name": "整月",
      },
      {
        "code": "9",
        "name": "其他",
      },
      ];
      var name;
      carTypes.forEach(item => {
        if (item.code === code) {
          name = item.name;
        }
      });
      return name;
    },
    getGoodsTypeNmae(code) {// 获取货物类型名称显示在表格 add by qzn 20190704  
      var goodsTypes = [
        {
          code: "1",
          name: "煤炭及制品"
        },
        {
          code: "2",
          name: "金属矿石"
        },
        {
          code: "3",
          name: "矿建材料及水泥"
        },
        {
          code: "4",
          name: "机械设备电器"
        },
        {
          code: "5",
          name: "轻工医药产品"
        },
        {
          code: "6",
          name: "鲜活农产品"
        },
        {
          code: "9",
          name: "其他"
        }
      ];
      var name;
      goodsTypes.forEach(item => {
        if (item.code === code) {
          name = item.name;
        }
      });
      return name;
    }
  }
};
</script>